iT邦幫忙

2022 iThome 鐵人賽

DAY 14
0

待捕

async def _upload_frame_to_s3_async(self, video):
        print('上傳frame slice', video)
        frame_list = glob.glob(os.path.join(video, '*.jpg'))
        video_name = video.split('/')[-1]
        filename_list = [os.path.split(frame)[1] for frame in frame_list]
        target_list = [
            (os.path.join(video, filename), os.path.join(
                'Car22', 'origin_img', video_name, filename))
            for filename in filename_list
        ]

        session = aioboto3.Session()
        semaphore = asyncio.Semaphore(1000)

        async def upload_file(bucket, path, key):
            async with semaphore:
                return await bucket.upload_file(path, key, ExtraArgs={'ContentType': 'image/jpeg'})

        async with session.resource("s3") as s3:
            bucket = await s3.Bucket('flow-drive-internal')
            await asyncio.gather(*[upload_file(bucket, path, key) for path, key in target_list])

上一篇
D13 - 常被忽略的責任-2 - 錯誤處理
下一篇
D16 - Design Pattern
系列文
寫個好的lib大家用吧!那些好用的lib常見的套路與想法25
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言